using Unity.Entities;
using Unity.Scenes;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Core
{
    public abstract partial class AuthoringScenesSystemGroup : ComponentSystemGroup
    {
        protected abstract string SystemGroupName { get; }
        private bool initialized = false;

        protected override void OnUpdate()
        {
            // 这个很重要，不然基于它的子系统不会被启用！！！！！（已验证！）
            base.OnUpdate();
            
            if (!initialized)
            {
                if (SceneManager.GetActiveScene().isLoaded)
                {
                    var subScene = Object.FindObjectOfType<SubScene>();
                    if (subScene != null)
                    {
                        Enabled = SystemGroupName == subScene.SceneName;
                        
                        Debug.Log($"{SystemGroupName} Enabled:" + Enabled);
                    }
                    else
                    {
                        Enabled = false;
                    }

                    initialized = true;
                }
            }
        }
    }
}